<?php

class WoguIndexAction extends CommonAction
{
    public function index() {
        vendor("common");
        global $_FANWE;
        FanweService::instance()->cache->loadCache('goods_category');

	 	$index_cids = $_FANWE['cache']['goods_category']['index'];
	 	$names = array();
	 	foreach($index_cids as $k => $cid) {
	 	    $cateinfo = $_FANWE['cache']['goods_category']['all'][$cid];
	 	    if($cateinfo['parent_id'] != 0) {
	 	        unset($index_cids[$k]);
	 	    } else {
	 	        $names[$cid] = $cateinfo['cate_name'];
	 	    }
	 	}
	 	
	 	$arr = include FANWE_ROOT.'/public/index.php';
	 	$this->assign("arr", $arr);
        $this->assign("index_cids", $index_cids);
        $this->assign("names", $names);
        $this->display();
    }
    
    public function doindex() {
        if(isset($_POST['data'])) {
            $data = $_POST['data'];
            $arr = array();
            foreach($data as $k => $v) {
                foreach($v as $k1 => $v1) {
                    $lines = explode("\r\n", $v1);
                    foreach($lines as $k2 => $v2) {
                        $arr[$k][$k1][] = explode('#', $v2);
                    }
                }
            }
            file_put_contents(FANWE_ROOT.'/public/index.php', "<?php\r\nreturn ".var_export($arr,true).";\r\n");
        }
        
		$this->assign('jumpUrl', u('index'));
		$this->success (L('EDIT_SUCCESS'));
    }
}
